﻿using System.Linq;
using NUnit.Framework;
using OpenWaves.Collections;

namespace OpenWaves.UnitTests
{
    [TestFixture]
    public class EnumerableExtensionsTests
    {
        [Test]
        public void GroupByTest()
        {
            var items = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

            Assert.That(items.GroupBy(20).Count(), Is.EqualTo(1));
            Assert.That(items.GroupBy(10).Count(), Is.EqualTo(1));
            Assert.That(items.GroupBy(5).Count(), Is.EqualTo(2));
            Assert.That(items.GroupBy(3).Count(), Is.EqualTo(4));
            Assert.That(items.GroupBy(2).Count(), Is.EqualTo(5));
            Assert.That(items.GroupBy(1).Count(), Is.EqualTo(10));

            var groups = items.GroupBy(3);
            var g0 = groups.ElementAt(0);
            var g1 = groups.ElementAt(1);
            var g2 = groups.ElementAt(2);
            var g3 = groups.ElementAt(3);

            Assert.That(g0, Is.EquivalentTo(new [] {1, 2, 3}));
            Assert.That(g1, Is.EquivalentTo(new[] { 4, 5, 6 }));
            Assert.That(g2, Is.EquivalentTo(new[] { 7, 8, 9 }));
            Assert.That(g3, Is.EquivalentTo(new[] { 10 }));
        }
    }
}